package cn.rcth.base.serivce.impl;

import cn.rcth.base.domain.RechargeCard;
import cn.rcth.base.mapper.RechargeCardMapper;
import cn.rcth.base.serivce.IRechargeCarSerivce;
import cn.rcth.base.util.MD5Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Transactional
public class RechargeCarSerivceImpl implements IRechargeCarSerivce {

    @Autowired
    private RechargeCardMapper rechargeCardMapper;

    @Override
    public String selectPasswordAndUpdateIp(String ip, String card) {

        RechargeCard rechargeCard = rechargeCardMapper.getRechargeCarByCard(card);
        if (rechargeCard != null){
            rechargeCard.setIp(ip);
            rechargeCard.setNumber(rechargeCard.getNumber() + 1);
            rechargeCard.setModifyTime(new Date());
            rechargeCardMapper.updateByPrimaryKey(rechargeCard);
            String password = rechargeCard.getPassword();
            return password;
        }else {
            return "没有查询到该卡号,请重新检查您的卡号是否正确";
        }
    }
}
